/**
 * 匹配替换表情符号
 * @param str {String}
 */
export const filterEmoticon = (str) => {
  if (!str) {
    return str
  }
  var face = {
    '[爱你]': 'd_aini',
    '[奥特曼]': 'd_aoteman',
    '[拜拜]': 'd_baibai',
    '[悲伤]': 'd_beishang',
    '[鄙视]': 'd_bishi',
    '[闭嘴]': 'd_bizui',
    '[馋嘴]': 'd_chanzui',
    '[吃惊]': 'd_chijing',
    '[哈欠]': 'd_dahaqi',
    '[打脸]': 'd_dalian',
    '[顶]': 'd_ding',
    '[doge]': 'd_doge',
    '[肥皂]': 'd_feizao',
    '[感冒]': 'd_ganmao',
    '[鼓掌]': 'd_guzhang',
    '[哈哈]': 'd_haha',
    '[害羞]': 'd_haixiu',
    '[汗]': 'd_han',
    '[微笑]': 'd_hehe',
    '[黑线]': 'd_heixian',
    '[哼]': 'd_heng',
    '[色]': 'd_huaxin',
    '[挤眼]': 'd_jiyan',
    '[可爱]': 'd_keai',
    '[可怜]': 'd_kelian',
    '[酷]': 'd_ku',
    '[困]': 'd_kun',
    '[白眼]': 'd_landelini',
    '[泪]': 'd_lei',
    '[马到成功]': 'd_madaochenggong',
    '[喵喵]': 'd_miao',
    '[男孩儿]': 'd_nanhaier',
    '[怒]': 'd_nu',
    '[怒骂]': 'd_numa',
    '[女孩儿]': 'd_numa',
    '[钱]': 'd_qian',
    '[亲亲]': 'd_qinqin',
    '[傻眼]': 'd_shayan',
    '[生病]': 'd_shengbing',
    '[草泥马]': 'd_shenshou',
    '[失望]': 'd_shiwang',
    '[衰]': 'd_shuai',
    '[睡]': 'd_shuijiao',
    '[思考]': 'd_sikao',
    '[太开心]': 'd_taikaixin',
    '[偷笑]': 'd_touxiao',
    '[吐]': 'd_tu',
    '[兔子]': 'd_tuzi',
    '[挖鼻]': 'd_wabishi',
    '[委屈]': 'd_weiqu',
    '[笑cry]': 'd_xiaoku',
    '[熊猫]': 'd_xiongmao',
    '[嘻嘻]': 'd_xixi',
    '[嘘]': 'd_xu',
    '[阴险]': 'd_yinxian',
    '[疑问]': 'd_yiwen',
    '[右哼哼]': 'd_youhengheng',
    '[晕]': 'd_yun',
    '[炸鸡啤酒]': 'd_zhajipijiu',
    '[抓狂]': 'd_zhuakuang',
    '[猪头]': 'd_zhutou',
    '[最右]': 'd_zuiyou',
    '[左哼哼]': 'd_zuohengheng',
    '[给力]': 'f_geili',
    '[互粉]': 'f_hufen',
    '[囧]': 'f_jiong',
    '[萌]': 'f_meng',
    '[神马]': 'f_shenma',
    '[威武]': 'f_v5',
    '[喜]': 'f_xi',
    '[织]': 'f_zhi',
    '[NO]': 'h_buyao',
    '[good]': 'h_good',
    '[haha]': 'h_haha',
    '[来]': 'h_lai',
    '[OK]': 'h_ok',
    '[拳头]': 'h_quantou',
    '[弱]': 'h_ruo',
    '[握手]': 'h_woshou',
    '[耶]': 'h_ye',
    '[赞]': 'h_zan',
    '[作揖]': 'h_zuoyi',
    '[伤心]': 'l_shangxin',
    '[心]': 'l_xin',
    '[蛋糕]': 'o_dangao',
    '[飞机]': 'o_feiji',
    '[干杯]': 'o_ganbei',
    '[话筒]': 'o_huatong',
    '[蜡烛]': 'o_lazhu',
    '[礼物]': 'o_liwu',
    '[绿丝带]': 'o_lvsidai',
    '[围脖]': 'o_weibo',
    '[围观]': 'o_weiguan',
    '[音乐]': 'o_yinyue',
    '[照相机]': 'o_zhaoxiangji',
    '[钟]': 'o_zhong',
    '[浮云]': 'w_fuyun',
    '[沙尘暴]': 'w_shachenbao',
    '[太阳]': 'w_taiyang',
    '[微风]': 'w_weifeng',
    '[鲜花]': 'w_xianhua',
    '[下雨]': 'w_xiayu',
    '[月亮]': 'w_yueliang'
  }
  var reg = /\[.+?\]/g
  return str.replace(reg, function (item, index) {
    return face[item] ? emotionImagePath(face[item]) : item
  })
}

/**
 * 获取表情图片
 * @param emotion {String}
 */
export const emotionImagePath = (emotion, title = '') => {
  let type = '@3x.png'
  return '<img src="/static/face/' + emotion + type + '" alt="' + title + '" class="face" />'
}

/**
 * 匹配话题
 * @param str {String}
 */
export const filterTopic = (str) => {
  var reg = /#([^#|.]+)#/
  return str.replace(reg, function (item, index) {
    return '<span class="topic element-clickable" data-type="topic">' + item + '</span>'
  })
}

/**
 * 匹配@
 * @param str {String}
 */
export const filterAt = (str) => {
  var reg = /@([^\s|/|:|@]+)/
  return str.replace(reg, function (item, index) {
    return '<span class="at element-clickable" data-type="at">' + item + '</span>'
  })
}

/**
 * 过滤动态标签
 * @param str {String}
 */
export const handleTextClick = (item) => {
  console.log(item)
}

/**
 * 过滤动态标签
 * @param str {String}
 */
export const filterTags = (str) => {
  if (!str) {
    return str
  }
  str = filterAt(str)
  str = filterTopic(str)
  str = filterEmoticon(str)
  return str
}
